package com.haibei.activity.common;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;

import com.common.uitl.SharePersistent;
import com.common.uitl.StringUtils;
import com.common.uitl.Tool;
import com.haibei.R;
import com.haibei.activity.BaseHaibeiActivity;

/**
 * 评论activity
 * @author wangzy
 */
public class CommentActivity extends BaseHaibeiActivity implements OnClickListener {

	private boolean isComment;
	private TextView mTextViewReplayTitle;
	private EditText mEditTextContentReply;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.isComment = getIntent().getBooleanExtra("comment", false);
		initView();
	}

	@Override
	public void initView() {
		setContentView(R.layout.activity_common_comment);
		mTextViewReplayTitle = findTextViewById(R.id.textViewReplayTitle);
		mEditTextContentReply = findEditTextById(R.id.editTextContentReply);
		mTextViewReplayTitle.setText(isComment == true ? "评论" : "回复");
		findButtonById(R.id.buttonReply).setOnClickListener(this);
		findViewById(R.id.buttonBack).setOnClickListener(this);
	}

	@Override
	protected void onPause() {
		super.onPause();
		String text = mEditTextContentReply.getText().toString();
		if (!StringUtils.isEmpty(text)) {
			SharePersistent.savePerference(this, "reply", text);
		}

	}

	@Override
	protected void onResume() {
		super.onResume();
		String t = SharePersistent.getPerference(this, "reply");
		if (!StringUtils.isEmpty(t)) {
			mEditTextContentReply.setText(t);
		}
	}

	@Override
	public void onClick(View v) {
		int vid = v.getId();
		switch (vid) {
		case R.id.buttonBack: {
			finish();
		}
			break;
		case R.id.buttonReply: {
			String coment=getInput(mEditTextContentReply);
			if(!StringUtils.isEmpty(coment) && coment.length()<=200){
				putDataBack(coment);
			}else{
				Tool.ToastShow(this, "请输入200字以内的内容!");
			}
		}
			break;
		default:
			break;
		}
	}

	private void putDataBack(String content) {
		Intent i = new Intent();
		i.setClass(this, CommentActivity.class);
		i.putExtra("data", content);
		setResult(RESULT_OK,i);
		finish();
	}
}
